package com.sleeping.mall.common.utils.result;

import org.apache.commons.lang.StringUtils;

import java.io.Serializable;

/**
 * 返回单个对象公用DTO
 * @author ChenDong
 * @date 2018/5/11
 */
public class ResponseWrapper<T> implements Serializable {

    private boolean success = true;

    private String msg = "";

    private T obj;

    public T getObj() {
        return obj;
    }

    public ResponseWrapper(ResponseWrapper<T> responseWrapper) {
        this.success = responseWrapper.isSuccess();
        this.msg = responseWrapper.getMsg();
        this.obj = responseWrapper.getObj();
    }

    public ResponseWrapper(boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }

    public ResponseWrapper(boolean success, String msg, T obj) {
        this.success = success;
        this.msg = msg;
        this.obj = obj;
    }

    public ResponseWrapper<T> setObj(T obj) {

        this.obj = obj;
        return this;
    }

    public ResponseWrapper(T obj) {
        this.obj = obj;
    }

    public ResponseWrapper() {
    }

    public boolean isSuccess() {
        if (StringUtils.isNotEmpty(msg)) {
            return false;
        }
        return success;
    }

    public ResponseWrapper<T> setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public ResponseWrapper<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }


}
